package com.string.practice;

import java.util.Random;

public class CheckCode {
    public static void main(String[] args) {
        char[] upper={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','z','y','z'};
        //char[] lower={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','z','y','z'};
        char[] code_number={0,1,2,3,4,5,6,7,8,9};
        Random r=new Random();
        char[] code_check=new char[4];
        int number;
        for (int i = 0; i < code_check.length; i++) {
            code_check[i]=upper[r.nextInt(upper.length)];
        }

        number=code_number[r.nextInt(code_number.length)];
        System.out.println(number);
        String code=new String(code_check);
//        System.out.println(code);
        code=code+number;
//        System.out.println(code);
        code=getString(code.toCharArray(),r);

        System.out.println(code);
    }

    private static String getString(char[] chars, Random r) {
        for (int i = 0; i < chars.length; i++) {
            char temp;
            temp = chars[i];
            chars[i] = chars[r.nextInt(chars.length)];
            chars[r.nextInt(chars.length)] = temp;
        }
        String result = new String(chars);
        return result;
    }
}
